GiaoPhieuThuPanel = Ext.extend(AbstractPanel, {
	layout : {
        type : 'vbox',
        align : 'stretch'
    },
    
	initComponent : function() {
		this.formLabel = new Ext.form.Label({
			cls : 'main-title',
			text : lang.text.menu.giaoPt.toUpperCase()
		});
		
		this.formLabelContainer = new Ext.Container({
			cls : 'field-align-center',
			items : [this.formLabel]
		});
		
		this.thuNganCombo = new Ext.form.ComboBox({
			name : 'thuNgan',
            fieldLabel : lang.text.giaoPt.chonThuNgan,
            selectOnFocus : true,
            width : 250,
            mode : 'local',
            valueField : 'id',
            displayField : 'maNv',
            forceSelection : true,
            triggerAction : 'all',
            store : new Ext.data.JsonStore({
                fields : ['id', 'maNv']
            })
		});
		
		this.xuatPhieuThuBtn = new Ext.Button({
			text : lang.text.giaoPt.xuatPhieuBanGiao
		});
		
		this.detailContainer = new Ext.Container({
			width : 500,
			layout : 'form',
			height : 500,
			items : [this.thuNganCombo,{xtype : 'spacer', height : 20},this.xuatPhieuThuBtn]
		});
		
		this.items = [this.formLabelContainer, {xtype : 'spacer', height : 20},this.detailContainer];
		GiaoPhieuThuPanel.superclass.initComponent.call(this);
	},
	
	afterRender : function() {
		GiaoPhieuThuPanel.superclass.afterRender.call(this);		
		
		this.initData();
		this.xuatPhieuThuBtn.on('click', this.handleXuatPhieuBanGiao, this);
	},
	
	handleXuatPhieuBanGiao : function(){
		var params = {'id' : this.thuNganCombo.getValue()};
        var url = "giaoPhieuThu/export?"+ Ext.urlEncode(params);
        Utility.processExportWaiting(url);
	},
	
	/**
	 * Pre-load data for screen.
	 */
	initData : function(){
		Ext.Ajax.request({
            url : 'giaoPhieuThu/loadListOfThuNgan',
            method : 'GET',
            scope : this,
            success : function(response, opts){
                var result = Ext.decode(response.responseText); 
                this.thuNganCombo.store.loadData(result.thuNgan);
                if(result.thuNgan.length > 0){
                	this.thuNganCombo.setValue(result.thuNgan[0].id);
                	this.thuNganCombo.focus(true);
                } else {
                	this.xuatPhieuThuBtn.disable();
                }
            }, 
            failure : Ext.emptyFn
        }, this);
	},
	
	defaultActionHandler : function(){
		this.handleXuatPhieuBanGiao();
	}
});